package com.example.study.rabbitmq.chat;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
public class ChatRabbitConfig {

    private final HashMap<String, Object> map = new HashMap<>();

    //队列
    @Bean
    public Queue chatQueue() {
        map.put("x-message-ttl", 10 * 1000);
        map.put("x-dead-letter-exchange","deadEx");
        map.put("x-dead-letter-routing-key","deadKey");
        return new Queue("chat_que", true, false, false, map);
    }

    //交换机
    @Bean
    public DirectExchange fanoutExchange() {
        return new DirectExchange("chatEx", true, false);
    }

    @Bean
    public Binding bindingCdc() {
        return BindingBuilder.bind(chatQueue()).to(fanoutExchange()).with("chatKey");
    }


    //队列
    @Bean
    public Queue deadQueue() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("x-message-ttl", 5 * 1000);
        return new Queue("dead_que", true, false, false, map);
    }

    //交换机
    @Bean
    public DirectExchange deadExchange() {
        return new DirectExchange("deadEx", true, false);
    }

    @Bean
    public Binding bindingdead() {
        return BindingBuilder.bind(deadQueue()).to(deadExchange()).with("deadKey");
    }

}
